<template>
  <div>
    <el-table
        :data="tableData"
        style="width: 100%"
        @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column
          prop="id"
          label="编号"
          width="180">
      </el-table-column>
      <el-table-column
          prop="ip"
          label="ip地址"
          width="180">
      </el-table-column>
      <el-table-column
          prop="name"
          label="访问方法">
      </el-table-column>
      <el-table-column
          prop="context"
          label="请求">
      </el-table-column>
      <el-table-column
          prop="createTime"
          label="访问时间">
      </el-table-column>
      <el-table-column
          prop="username"
          label="详情">
      </el-table-column>
      <el-table-column v-slot="s">
        <el-button @click="delById(s.row.id)">删除</el-button>
      </el-table-column>
    </el-table>
    <el-pagination
        @current-change="goPage"
        :page-size="size"
        layout="total, prev, pager, next"
        :total="total">
    </el-pagination>
    <el-button @click="delAll">批量删除</el-button>
  </div>
</template>

<script>
export default {
  name: "LogsView",
  data() {
    return {
      tableData:[],
      logs:{},
      size:3,
      total:0,
      current:1,
    }
  }, methods: {
    delAll(){
      this.axios.post("/logs/delAll?ids="+this.ids).then(()=>{
        this.$message.success("删除成功");
        this.list();
      })
    },
    handleSelectionChange(rows){
      console.log(rows);
      this.ids = rows.map(item=>item.id).join(",");
      console.log(this.ids)
    },
    delById(id){
      this.axios.post("/logs/delById?id="+id).then(()=>{
        this.$message.success("删除成功");
        this.list();
      })
    },
    goPage(page){
      this.current = page;
      this.list();
    },
    list(){
      this.axios.post("/logs/logsList?current="+this.current+"&size="+this.size,this.logs).then(res=>{
        this.tableData = res.data.data.list;
        this.total = res.data.data.total;
      })
    }
  }, created() {
    this.list();
  }
}
</script>

<style scoped>

</style>
